
import cloud from '@lafjs/cloud'
import nw from "nw-lafjs";
import {fail, ok} from "@/utils/responseUtil";
const db = cloud.database()
const _ = db.command

export default async function (ctx: FunctionContext) {
  //1.逻辑删除
  let body:any[] = ctx.body
  /**
   * ["1"]
   */

  //1。数据校验
  if (!nw.util.isArray(body)||body.length===0){
    return fail("数据不合法")
  }

  let dataJson = {
    deleted:1
  }
  //2.修改数据即可
  let num = await nw.db.update({
    dbName:"admin",
    whereJson:{
      _id:_.in(body)
    },
    dataJson:dataJson
  })

  if (num<=0){
    return fail("删除失败")
  }
  //需要删除对应的角色关系
  await nw.db.update({
    dbName:"adminRole",
    whereJson:{
      adminId:_.in(body)
    },
    dataJson:dataJson
  })

  return  ok("删除成功")
}
